import {Component, OnInit} from '@angular/core';
import {Page} from '../../../public/util/page';
import {UserService} from '../user.service';
import {Enums, JlbAccountState} from '../../../public/setting/enums';
import {SettingUrl} from '../../../public/setting/setting_url';
import {MainService} from '../../../public/service/main.service';

@Component({
  selector: 'app-user-jlb-list',
  templateUrl: './user-jlb-list.component.html',
  styleUrls: ['./user-jlb-list.component.scss']
})
export class UserJlbListComponent implements OnInit {
  public searchParams: any = {};//搜索参数
  public userJlbList: Page = new Page(); //供应商
  public _loading: boolean = false;
  public routerLinks = SettingUrl.ROUTERLINK;//路由
  public states = Enums.userJlbState;       // 状态
  public jlbAccountState = JlbAccountState;
  public jlbStates: Array<any> = [];

  constructor(private userService: UserService, private mainService: MainService) {
    this.jlbStates = this.mainService.getEnumDataList(Enums.userJlbState);
    this.jlbStates.unshift({key: '', val: '全部'});
  }

  ngOnInit() {
    this.queryUserJlbList();
  }

  /**
   * 查询userJlb列表
   * @param curPage 当前页
   */
  queryUserJlbList(curPage?: number) {
    this._loading = true;
    if (curPage) this.userJlbList.curPage = curPage;//当有页码时，查询该页数据
    this.userJlbList.params = {
      state: this.searchParams.state, //state
      account: this.searchParams.account, //account
      curPage: this.userJlbList.curPage, //目标页码
      pageSize: this.userJlbList.pageSize, //每页条数
    };
    this.userService.getUserJlbList(this.userJlbList.params).then((res: Page) => {
      this._loading = false;
      this.userJlbList = res;
    }).catch(err => {
      this._loading = false;
    });
  }

  /**
   * 重置搜索
   */
  resetSearch() {
    this.searchParams = {};
    this.queryUserJlbList(1);
  }
}
